#include "debug.h"
#include <stdbool.h>
#include "key.h"
#include "common.h"
#include "CharlieplexingLed.h"

/* Global typedef */
#ifdef RAZOR_DEBUG
#define log_printf(...) printf(__VA_ARGS__)
#else
#define log_printf(...)
#endif



int main(void)
{
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
    SystemCoreClockUpdate();
    Delay_Init();
#if (SDI_PRINT == SDI_PR_OPEN)
    SDI_Printf_Enable();
#else
//    USART_Printf_Init(115200);
#endif
//    printf("SystemClk:%d\r\n", SystemCoreClock);
//    printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );

    Delay_Ms(1000);
    CharlieplexingLed_init();
    uint8_t CharlieplexingLedSize = CharlieplexingLedGetSize();
    uint8_t led = (CharlieplexingLedSize - 1);

    while(1)
    {
        CharlieplexingLed_write_pin(led, 1);
        Delay_Ms(12);
        CharlieplexingLed_write_pin(led, 0);
    //    Delay_Ms(50);
        if (led == 0) {
            Delay_Ms(1000);
        }
        led = led > 0 ? (led - 1) : (CharlieplexingLedSize - 1);
    }
}
